//
//  PhotoMainView.m
//  OAProject
//
//  Created by yhj on 2017/2/23.
//  Copyright © 2017年 cdnunion. All rights reserved.
//

#import "PhotoMainView.h"

@interface PhotoMainView ()<UITextViewDelegate>

@property(nonatomic,strong)UITextView *textView;

@property(nonatomic,strong)UIImageView *imageView;

@end

@implementation PhotoMainView

-(void)setImage:(UIImage *)image
{
    _image=image;
    self.imageView.image=image;
    [self setNeedsLayout];
}

// textView
-(UITextView *)textView
{
    if (!_textView) {
        _textView=[UITextView new];
        _textView.backgroundColor=[UIColor colorFromHexString:@"#ebebeb"];
         ViewBorderRadius(_textView,kmargin,1,Color999999);
        _textView.delegate=self;
        [self addSubview:_textView];
    }
    return _textView;
}

// imageView
-(UIImageView *)imageView
{
    if (!_imageView) {
        _imageView=[UIImageView new];
        _imageView.backgroundColor=ClearColor;
        [self addSubview:_imageView];
        // 圆角和边框
        ViewBorderRadius(_imageView,kmargin,1,ClearColor);
    }
    return _imageView;
}


-(void)layoutSubviews
{
    [super layoutSubviews];

    self.textView.frame=CGRectMake(kmargin,kmargin,APPW-kmargin*4,kmargin*10);
    [self.textView becomeFirstResponder];

    self.imageView.frame=CGRectMake(kmargin,0,kmargin*8,kmargin*8);
    self.imageView.left=self.textView.left;
    self.imageView.top=self.textView.bottom+kmargin;
}


-(void)textViewDidEndEditing:(UITextView *)textView
{
    self.content=textView.text;
}

@end
